package com.hyf.util;

import com.hyf.bean.User;
import mapper.UserMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class UserMapperTest {
    SqlSession session;
    UserMapper mapper;
    @Before
    public void a(){
        SqlSessionFactory factory = MyBatisutil.getSqlSessionFactory();
        session = factory.openSession(true);
        mapper = session.getMapper(UserMapper.class);
    }
    @After
    public void b(){
        session.close();
    }
   @Test
    public void selectAll(){
       for(User user:mapper.selectAll()){
           System.out.println(user);
       }
   }
    @Test
    public void selectByUser(){
        User u=new User();
//        u.setUsername("a");
//        u.setPassword("a");
        for(User user:mapper.selectByUser(u))   {
            System.out.println(user);
        }
    }
    @Test
    public void selectByUserOne(){
        User u=new User();
        u.setUsername("a");
        u.setPassword("a");
        for(User user:mapper.selectByUserOne(u))   {
            System.out.println(user);
        }
    }
    @Test
    public void updateUser(){
        User u=new User();
        u.setUid(7);
        u.setUsername("a");
        u.setPassword("a");
        mapper.updateByUser(u);
    }
//    @Test
//    public void trimTest(){
//        mapper.trimTest();
//    }
    @Test
    public void deleteByArray(){
        int [] ids={4,5,6};
        mapper.deleteByArray(ids);
    }
    @Test
    public void insertList(){
        List<User> list=new ArrayList<>();
        list.add(new User("a", "a","a"));
        list.add(new User("b", "b","b"));
        list.add(new User("a1", "a1","a1"));
        list.add(new User("b1", "b1","b1"));
        list.add(new User("c", "c","c"));
        mapper.insertList(list);
    }
}
